package com.proj.dao.impl;

import com.proj.dao.UserDao;
import com.proj.entities.UserEntity;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

public final class UserDaoImpl extends HibernateDaoSupport implements UserDao
{
    @Override
    public UserEntity getUser(String userName)
    {
        List<UserEntity> getByUserName = getHibernateTemplate().findByNamedQueryAndNamedParam("getByUserName",
                "userName", userName);
        if (getByUserName == null || getByUserName.isEmpty())
        {
            return null;
        }
        else
        {
            return getByUserName.get(0);
        }
    }

    @Override
    public List<UserEntity> getAllUsers()
    {
        return getHibernateTemplate().loadAll(UserEntity.class);
    }

    @Override
    public long createUser(UserEntity userEntity)
    {
        return (Long) getHibernateTemplate().save(userEntity);
    }

    @Override
    public void updateUser(UserEntity userEntity)
    {
        getHibernateTemplate().update(userEntity);
    }

    public void deleteUser(String userName)
    {
        
    }
}
